﻿Public Class ucPerito
    Private _ehParaSelecionarTodos As Boolean = True
    Private peritoBO As New usuarioBO
    Private lista As New Generic.List(Of usuarioVO)
    Private _permiteDigitacao As Boolean = False

    Public Property PERMITEDIGITACAO As Boolean
        Get
            Return _permiteDigitacao
        End Get
        Set(value As Boolean)
            _permiteDigitacao = value
        End Set
    End Property

    Public Property getPeritoSelecionado() As Integer

        Get
            Return cmbPerito.SelectedValue

        End Get

        Set(ByVal value As Integer)

            cmbPerito.SelectedValue = value

        End Set

    End Property




    Public Property ehSelecionarTodos() As Boolean

        Get
            Return _ehParaSelecionarTodos

        End Get

        Set(ByVal value As Boolean)

            _ehParaSelecionarTodos = value

        End Set

    End Property


    Public Property ativaAutocomplete() As Boolean

        Get
            Return cmbPerito.AutoCompleteMode

        End Get

        Set(ByVal value As Boolean)

            cmbPerito.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            cmbPerito.AutoCompleteSource = AutoCompleteSource.ListItems
        End Set

    End Property


    Public Property getNomePeritoSelecionado() As String

        Get
            Return CType(cmbPerito.SelectedItem, usuarioVO).NOME

        End Get

        Set(ByVal value As String)


        End Set

    End Property

    Public Property getMaspPeritoSelecionado() As String

        Get
            Return CType(cmbPerito.SelectedItem, usuarioVO).MASP

        End Get

        Set(ByVal value As String)


        End Set

    End Property

    Private Sub populaDados()

        Try

            If Not DesignMode Then
                If _ehParaSelecionarTodos Then
                    lista = peritoBO.getUsuariosSecao()
                Else
                    lista = peritoBO.getUsuariosSecao(10)
                End If
                If lista.Count = 0 Then
                    cmbPerito.Items.Insert(0, "Não há peritos cadastrados para esta seção")
                    cmbPerito.SelectedIndex = 0
                Else
                    cmbPerito.DisplayMember = "NOME"
                    cmbPerito.ValueMember = "ID_USUARIO"
                    cmbPerito.DataSource = lista

                    If Not _ehParaSelecionarTodos Then
                        cmbPerito.SelectedValue = Login.Usuario.USUARIOLOGADO.ID_USUARIO
                    End If

                End If
            End If

        Catch ex As Exception

            generica.gravaErro(ex)

        End Try


    End Sub


    Private Sub ucPerito_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not DesignMode Then

            populaDados()
        End If

    End Sub

    Private Sub cmbPerito_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cmbPerito.KeyPress

        If PERMITEDIGITACAO Then
            e.Handled = False
        Else
            e.Handled = True
        End If

    End Sub
End Class
